import Vue from 'vue'
import Router from 'vue-router'

// 初始路由集
const layout = () => import('../components/layout'),
    home = () => import('../page/home'),
    apply = () => import('../page/apply'),
    register = () => import('../page/register'),
    shop = () => import('../components/shop'),
    history = () => import('../page/history'),
    historyDetail = () => import('../page/history-detail'),
    siteAudit = () => import('../page/site-audit'),
    constantRouterMap = [
        {
            path: '/',
            name: 'index',
            redirect: '/home',
            component: layout,
            children: [
                {
                    path: '/home',
                    name: 'home',
                    component: home,
                    meta: {
                        title: '首页',
                        keepAlive: false
                    }
                },
                {
                    path: '/apply',
                    name: 'apply',
                    component: apply,
                    meta: {
                        title: '口罩实名预约',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'shop',
                            name: 'shop',
                            component: shop,
                            meta: {
                                title: '门店选择',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/register',
                    name: 'register',
                    component: register,
                    meta: {
                        title: '注册',
                        keepAlive: false
                    },
                    children: [
                        {
                            path: 'shop',
                            name: 'shop',
                            component: shop,
                            meta: {
                                title: '门店选择',
                                keepAlive: false
                            }
                        }
                    ]
                },
                {
                    path: '/history',
                    name: 'history',
                    component: history,
                    meta: {
                        title: '历史预约',
                        keepAlive: false
                    }
                },
                {
                    path: '/history-detail',
                    name: 'historyDetail',
                    component: historyDetail,
                    meta: {
                        title: '历史预约详情',
                        keepAlive: false
                    }
                },
                {
                    path: '/site-audit',
                    name: 'siteAudit',
                    component: siteAudit,
                    meta: {
                        title: '门店审计',
                        keepAlive: false
                    }
                }
            ]
        }
    ]

let router = new Router({
    mode: 'history',
    routes: constantRouterMap
})

// 路由跳转前更改网页标题
router.beforeEach((to, from, next) => {
    // if (to.meta && to.meta.title) {
    //     document.title = to.meta.title
    // }
    next()
})

Vue.use(Router)

export default router
